﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KxParser.Parser.Lr0
{
	/// <summary>
	/// Grammar defined using Backus-Naur form
	/// </summary>
	/// <see cref="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form"/>
	public class BnfGrammar
	{
		public string Name { get; set; }
		public string Rule { get; set; }
		//public List<string> RuleItems { get { return Rule.Split(Global.RuleItemSeparator).ToList(); } }

		/// <summary>
		/// Backus-Naur grammar constructor
		/// </summary>
		/// <param name="name">Grammar name</param>
		/// <param name="rule">Grammar rule</param>
		public BnfGrammar(string name, string rule)
		{
			Name = name;
			Rule = rule;
		}

		public override string ToString()
		{
			return Name + " -> " + Rule;
		}

		public override bool Equals(object obj)
		{
			if(typeof(BnfGrammar).IsAssignableFrom(obj.GetType()))
			{
				BnfGrammar bnf2 = ((BnfGrammar)obj);
				return Name.Equals(bnf2.Name) && Rule.Equals(bnf2.Rule);
			}
			return false;
		}
	}
}
